package com.itic.codeGen.codeGenerator.workLine.implement;

import java.util.ArrayList;
import java.util.List;

import com.itic.codeGen.codeGenerator.util.CommonUtils;
import com.itic.codeGen.codeGenerator.workLine.PartGenerator;

public class DaoGenerator implements PartGenerator {

    private static final String BaseDao = "com.itic.appbase.framework.common.persistence.dao.CrudDao";
    private static final String IticDaoAnnotation = "com.itic.appbase.framework.common.annotation.IticDBDao";
    private static final String Annotation = "@IticDBDao";

    private String baseDaoClz;
    private String packageName;
    private String domainName;
    private ArrayList<String> imports = new ArrayList<String>();
    private ArrayList<String> headers = new ArrayList<String>();
    private String extend;

    public DaoGenerator(String baseDaoClz, String packageName, String domainName) {
	super();
	this.baseDaoClz = baseDaoClz;
	this.packageName = packageName;
	this.domainName = domainName;
    }

    @Override
    public List<String> getImports() {
	imports.add(IticDaoAnnotation);
	imports.add(BaseDao);
	imports.add(baseDaoClz + CommonUtils.PKG_SPLITER + domainName
	        + CommonUtils.BASE_MAPPER);
	imports.add(packageName + CommonUtils.PKG_SPLITER + domainName);
	imports.add(packageName + CommonUtils.PKG_SPLITER + domainName + CommonUtils.BASE_EXAMPLE);
	return imports;
    }

    @Override
    public List<String> getHeaders() {
	headers.add(Annotation);
	return headers;
    }

    @Override
    public String getExtend() {
	extend = this.parseDaoExtends(domainName, BaseDao);
	return extend;
    }

    @Override
    public List<String> getImplement() {
	return null;
    }

    @Override
    public List<String> getBody() {
	return null;
    }

    @Override
    public String getXMLName() {
	return null;
    }

    public String getBaseDaoClz() {
	return baseDaoClz;
    }

    public void setBaseDaoClz(String baseDaoClz) {
	this.baseDaoClz = baseDaoClz;
    }

    public String getPackageName() {
	return packageName;
    }

    public void setPackageName(String packageName) {
	this.packageName = packageName;
    }

    public String getDomainName() {
	return domainName;
    }

    public void setDomainName(String domainName) {
	this.domainName = domainName;
    }

    public void setImports(ArrayList<String> imports) {
	this.imports = imports;
    }

    public void setHeaders(ArrayList<String> headers) {
	this.headers = headers;
    }

    public void setExtend(String extend) {
	this.extend = extend;
    }

    /**
     * 
     * @Title: parseDaoExtends
     * @param domainName
     * @param basedao
     * @return
     * @throws
     */
    private String parseDaoExtends(String domainName, String basedao) {
	StringBuilder sb = new StringBuilder("");
	sb.append(domainName + CommonUtils.BASE_MAPPER);
	sb.append(",");
	sb.append(CommonUtils.getClzName(basedao) + "<" + domainName + "," + domainName + CommonUtils.BASE_EXAMPLE
	        + ">");
	return sb.toString();
    }

}
